package com.hogan.basiclibrary.base.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * Created by chenhu on 2017/10/31.
 */

public abstract class BaseViewFragment extends BaseFragment {
    protected View rootView;

    public BaseViewFragment() {

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null == rootView) {
            if (0 == getLayoutResId()) {
                new RuntimeException("fragment layout can't be empty");
            }
            rootView = inflater.inflate(getLayoutResId(), container, false);
        }
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        onLogicControl();
    }

    public abstract int getLayoutResId();

    public abstract void onLogicControl();

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unBindPresent();
    }

    /**
     * 解除绑定，防止内在泄漏
     */
    public abstract void unBindPresent();

}
